package top.kent90.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import top.kent90.common.object.Result;
import top.kent90.dao.ZczyItemDao;
import top.kent90.pojo.ZczyItem;

import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class ZczyItemServiceImpl implements ZczyItemService {
    @Autowired
    ZczyItemDao dao;
    /**
     * 根据条件查询项目
     *
     */
    @Override
    public Result queryShowItem(String pageNum, String pageSize, String title, Integer status, Integer type) {
        Map<String,Object> map = new HashMap<>();
        map.put("title",title);
        map.put("status",status);
        map.put("type",type);
        PageHelper.startPage(Integer.parseInt(pageNum),Integer.parseInt(pageSize));
        List<ZczyItem> rsList = dao.queryShowItem(map);
        PageInfo pg = new PageInfo(rsList);
         return new Result("0","",pg.getTotal(),pg.getList());
    }
        /**
         * 根据项目id查询项目详情
         * */
    @Override
    public Result queryItemById(Integer id) {

        ZczyItem item = dao.queryItemById(id);

        List<ZczyItem> rsList = new ArrayList<>();
        rsList.add(item);
        return new Result("0","",1L,rsList);
    }

    @Override
    public int updItemStatus(String id, String status) {
        Map<String,Object> map =new HashMap<>();
        map.put("id",Integer.parseInt(id));
        map.put("status",Integer.parseInt(status));
        String updatetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());

        map.put("updatetime",updatetime);
        int rs = dao.updItemStatus(map);
        return rs;
    }
    /**
     * 项目回收站
     */

}
